c# byte array to string

35

c# string to byte array -

string author = "Mahesh Chand";  
// Convert a C# string to a byte array  
byte[] bytes = Encoding.ASCII.GetBytes(author);  

// Convert a byte array to a C# string. 
string str = Encoding.ASCII.GetString(bytes);

convert system.byte a string c# -

string result = System.Text.Encoding.UTF8.GetString(byteArray);

c# byte array to string -

var str = System.Text.Encoding.Default.GetString(result);

c# string to byte array -

// Convert a string to a C# byte[]
//change encoding depending on your data
string someText = "some data as text.";
byte[] bytes = Encoding.ASCII.GetBytes(author);

// Convert a byte array to a C# string    
string str = Encoding.ASCII.GetString(bytes);  
Console.WriteLine(str);

convert bytes to string and back c# -

string base64 = Convert.ToBase64String(bytes);
byte[] bytes = Convert.FromBase64String(base64);

Comments

Submit
0 Comments